package com.campus.service.impl;

import com.campus.dao.StudentDao;
import com.campus.model.Student;
import com.campus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;

    @Override
    public Student createStudent(Student managerStudent) throws Exception {
        int ret = studentDao.insertStudent(managerStudent);
        if (ret > 0) {
            return managerStudent;
        }else{
            throw new Exception("fail to create");
        }
    }

    @Override
    public List<Student> importStudentsFromExcel(File excelFile) {
        return studentDao.importStudentsFromExcel(excelFile);
    }

    @Override
    public int batchImportStudents(List<Student> students) {

        return studentDao.batchImportStudents(students);
    }

    @Override
    public Student approveStudent(Integer id) {
        studentDao.approveStudent(id);
        return studentDao.findById(id);
    }

    @Override
    public int batchApproveStudent(List<Integer> studentIds) {
        return studentDao.batchApproveStudents(studentIds);
    }
}
